using System;
using System.Collections.Generic;
using System.Text;
using CMS.BIZ;
using AAM.BIZ;
using AAM.DAL;
using AAM.SQL;

namespace CMS.BOP
{
    public class SqlBizDownloadFolderProvider : SqlBizObjectProvider<BizDownloadFolder>
    {

        public BizDownloadFolder Read(int downloadFolderID)
        {
            return Read(new ObjectID(BizDownloadFolder.ObjectType, new object[] { downloadFolderID }));
        }
        public bool Delete(int downloadFolderID)
        {
            return Delete(new ObjectID(BizDownloadFolder.ObjectType, new object[] { downloadFolderID }));
        }
        public BizDownloadFolder Find(int downloadFolderID)
        {
            return Find(new ObjectID(BizDownloadFolder.ObjectType, new object[] { downloadFolderID }));
        }

        public List<BizDownloadFolder> ReadByFolder(int? parentFolderID)
        {
            Command command;
            string order = " ORDER BY FolderName";
            if (parentFolderID == null)
            {
                command = Connection.CreateCommand("SELECT * FROM " + Table.TableName + " WHERE ParentFolderID IS NULL" + order);
            }
            else
            {
                command = Connection.CreateCommand("SELECT * FROM " + Table.TableName + " WHERE ParentFolderID=?" + order);
                command.AddParameter(parentFolderID);
            }
            return CreateListFromCommand(command);
        }
    }
}
